package org.example.entity;

import org.apache.commons.lang3.StringUtils;
import org.example.exception.CourseCreateException;

import java.util.Set;

public class Course {
    private String courseId;

    private String courseName;

    private Integer credit;

    public Course() {
    }

    public Course(String courseId, String courseName, Integer credit) {
        if(isIllegal(courseId,courseName,credit)){
            throw new CourseCreateException("课程编号名称学分不能为空且学分为正整数！");
        }
        this.courseId = courseId;
        this.courseName = courseName;
        this.credit = credit;
    }

    //TODO 使用StringUtils类
    public boolean isIllegal(String courseId, String courseName, Integer credit) {
        return StringUtils.isBlank(courseId)||StringUtils.isBlank(courseName)||credit==null||credit<=0;
    }

    @Override
    public String toString() {
        return "Course{" +
                "courseId='" + courseId + '\'' +
                ", courseName='" + courseName + '\'' +
                ", credit=" + credit +
                '}';
    }

    public String getCourseId() {
        return courseId;
    }

    public void setCourseId(String courseId) {
        this.courseId = courseId;
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public Integer getCredit() {
        return credit;
    }

    public void setCredit(Integer credit) {
        this.credit = credit;
    }
}
